package com.cx.filter;

import com.cx.interceptor.Status;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "UserLoginFilter" ,urlPatterns = "/*/personalcenter/*")
public class UserLoginFilter implements Filter {
    public void destroy() {
    }
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        System.out.println("------------filter-----------");
        Object login = Status.map.get("login");
        HttpServletResponse response = (HttpServletResponse)resp;
        System.out.println(1);
        System.out.println("login="+login);
        if("1" == login){
            chain.doFilter(req, resp);
        }else {
            response.sendRedirect("http://localhost:63342/sdkd-parent/web/webapp/user/html/login.html");
        }

    }

    public void init(FilterConfig config) throws ServletException {

    }

}
